class LogsUtil {
  /// 黑色 Black
  static const String verboseColor = '\x1b[30m';

  /// 蓝色 Blue
  static const String debugColor = '\x1b[34m';

  /// 绿色 Green
  static const String infoColor = '\x1b[32m';

  /// 橙色(暂时用黄色 Light yellow)
  static const String warningColor = '\x1b[93m';

  /// 红色 Light red
  static const String errorColor = '\x1b[91m';

  /// 白色 White
  static const String defaultColor = '\x1b[97m';

  static const int verboseLevel = 0;
  static const int debugLevel = 1;
  static const int infoLevel = 2;
  static const int warningLevel = 3;
  static const int errorLevel = 4;

  /// 默认INFO等级
  static int defaultMinLevel = 1;

  /// 是否显示日志
  static bool isShowLogs = true;

  /// dart.vm.product 环境标识位 Release为true debug 为false
  static bool isRelease = bool.fromEnvironment("dart.vm.product") && isShowLogs;

  /// VERBOSE
  static void v(String tag, Object message) {
    if (!isRelease)
      _printLog(tag, '[VERBOSE] -> ', message, verboseLevel, verboseColor);
  }

  /// DEBUG
  static void d(String tag, Object message) {
    if (!isRelease)
      _printLog(tag, '[DEBUG] -> ', message, debugLevel, debugColor);
  }

  /// INFO
  static void i(String tag, Object message) {
    if (!isRelease) _printLog(tag, '[INFO] -> ', message, infoLevel, infoColor);
  }

  /// WARNING
  static void w(String tag, Object message) {
    if (!isRelease)
      _printLog(tag, '[WARNING] -> ', message, warningLevel, warningColor);
  }

  /// ERROR
  static void e(String tag, Object message, {Exception e}) {
    if (!isRelease)
      _printLog(tag, '[ERROR] -> ', message, errorLevel, errorColor);
  }

  /// 设置日志等级
  static void setMinLevel(int level) {
    defaultMinLevel = level;
  }

  /// 打印日志
  static void _printLog(String tag, String levelText, Object message, int level,
      [color = defaultColor]) async {
    StringBuffer sb = StringBuffer();
    sb..write(levelText)..write(tag ?? '')..write(': ')..write(message);
    if (level >= defaultMinLevel) {
      /// print('$color ${sb.toString()}'); $color打印日志的颜色
      print('${sb.toString()}');
    }
  }

  /// 上传日志
  static void uploadLogs(int ada, String amwayId, String content,
      String deviceId, int timeStamp, type) {}
}
